package com.ywk.base.common.office.excel.easypoi;

import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.view.PoiBaseView;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * @Author zbh
 * @Date 2024/10/20
 */
public class EasyPoiTest {

    @GetMapping("/exportReport")
    public void export(ModelMap map, HttpServletResponse response, HttpServletRequest request){
        try {
            List<StudentReportResponse> studentReportData = new ArrayList<>();
            StudentReportResponse student = new StudentReportResponse();
            student.setGender("男");
            student.setName("测试用户");
            studentReportData.add(student);
            ExportParams params = new ExportParams("学生报表", "学生报表", ExcelType.HSSF);
            map.put(NormalExcelConstants.DATA_LIST, studentReportData);
            map.put(NormalExcelConstants.CLASS, StudentReportResponse.class);
            map.put(NormalExcelConstants.PARAMS, params);
            map.put(NormalExcelConstants.FILE_NAME, "学生报表");
            PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);
        } catch (Exception e) {
            System.out.println("导出学生报表报错："+e);
        }
    }

    public void exportWithMultiThread(){
        Integer studentTotal = 1000000;
        Integer pageSize = 250000;
        int pageTotal = studentTotal % pageSize == 0 ? studentTotal / pageSize : studentTotal / pageSize + 1;
        CountDownLatch latch = new CountDownLatch(pageTotal);
        for (int i = 0; i < pageTotal; i++) {

        }

    }
}
